// 封装消息提示
import { ElMessage, ElLoading } from 'element-plus'
import toast from './toast'
import store from '../store'
export const message = ({type, text, duration,showClose = false}) => {

    if (store.state.isStylePc) {
        ElMessage({
            type,
            message: text,
            duration: duration || 2000,
            center: true,
            showClose
        })
    } else {
        if (type == 'error') {
            type = 'fail'
        } else if (type == 'info') {
            type = 'text'
        }
        toast({ type, text, duration: duration || 2000 })
    }
}

export const loading = ({ text, spinner, background }) => {
    let result = undefined;
    if (store.state.isStylePc) {
        result = ElLoading.service({
            fullscreen: true,
            lock: true,
            text: text || '加载中',
            spinner: spinner || 'el-icon-loading',
            background: background || 'rgba(0, 0, 0, 0.7)'
        })
    } else {
        result = toast({
            type: "loading",
            text: text || "加载中...",
            duration: 0,
            forbidClick: true
        })
    }
    return result
}
